// 读取单个"text/csv"节点输入数据
import { cloneDeep } from 'lodash'

export default {
  inject: ['root','flowchartId'],
  data() {
    return {
      formModel: {},
      inputData: [],
      nodeName:''
    }
  },
  created() {
    const { getSelected, save, find } = this.root.propsAPI
    const Model = getSelected()[0].getModel()
    // 拷贝当前节点的信息
    this.formModel = Object.assign({}, cloneDeep(Model))
    // 读取上一个节点信息，获取当前节点的入射边
    const flowchartData = save()
    // 当前的图没有边
    if (!flowchartData.edges) {
      return
    }
    const inputEdges = flowchartData.edges.filter(edge => {
      return edge.target === Model.id
    })
    // 当前的节点没有边
    if (inputEdges.length < 1) {
      return
    }
    const inputEdge = inputEdges[0]
    // 读取上一节点的输入数据
    const inputModel = find(inputEdge.source).getModel()
    // 输入节点需是已经执行过
    if (inputModel.executed) {
      this.formModel.inputNode = inputEdge.source
      this.inputData = inputModel.config.output
      this.nodeName = inputModel.alname
    }
  }
}
